<template>
  <div class="app-container">
    <Table :table="dataTable">
    </Table>
    <div
      class="Pagination"
      style="text-align: left;margin-top: 10px;"
    >
      <el-pagination
        v-if="pageshow"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="limit"
        layout="total, prev, pager, next"
        :total="count"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import Table from "@/components/Table/index";
import { fetchOvuolaDataDetail } from "@/api/chart";
import format from "date-format";
export default {
  data() {
    return {
      //总页码
      count: 0,
      //单页行数
      limit: 20,
      //页码
      currentPage: 1,
      dataTable: {
        loading: false,
        border: true,
        hasOperation: true,
        tr: [],
        data: [],
        operation: {}
      },
      pageshow: true
    };
  },
  components: {
    Table
  },
  mounted() {
    this.getOvuolaChart();
  },
  methods: {
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getOvuolaChart();
    },
    search() {
      this.currentPage = 1;
      this.pageshow = false;
      this.getOvuolaChart();
      this.$nextTick(() => {
        this.pageshow = true;
      });
    },

    async getOvuolaChart() {
      this.dataTable.hasOperation = false;
      this.dataTable.loading = true;
      if (this.$route.query.id == "1") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "天猫销售量",
            prop: "tOvuola",
            show: true
          },
          {
            id: "3",
            label: "微盟销售量",
            prop: "wOvuola",
            show: true
          },
          {
            id: "4",
            label: "小红书销售量",
            prop: "rOvuola",
            show: true
          },
          {
            id: "5",
            label: "拼多多销售量",
            prop: "pOvuola",
            show: true
          }
        ];
      } else if (this.$route.query.id == "2") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "天猫销售量",
            prop: "tHead",
            show: true
          },
          {
            id: "3",
            label: "微盟销售量",
            prop: "wHead",
            show: true
          },
          {
            id: "4",
            label: "小红书销售量",
            prop: "rHead",
            show: true
          },
          {
            id: "5",
            label: "拼多多销售量",
            prop: "pHead",
            show: true
          }
        ];
      } else if (this.$route.query.id == "3") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "天猫销售量",
            prop: "tStraw",
            show: true
          },
          {
            id: "3",
            label: "微盟销售量",
            prop: "wStraw",
            show: true
          },
          {
            id: "4",
            label: "小红书销售量",
            prop: "rStraw",
            show: true
          },
          {
            id: "5",
            label: "拼多多销售量",
            prop: "pStraw",
            show: true
          }
        ];
      } else if (this.$route.query.id == "4") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "公众号咨询数",
            prop: "pubConsult",
            show: true
          }
        ];
      } else if (this.$route.query.id == "5") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "天猫咨询数",
            prop: "tConsult",
            show: true
          }
        ];
      } else if (this.$route.query.id == "6") {
        this.dataTable.tr = [
          {
            id: "1",
            label: "时间",
            prop: "time",
            show: true
          },
          {
            id: "2",
            label: "拼多多",
            prop: "pingConsult",
            show: true
          }
        ];
      }

      const res = await fetchOvuolaDataDetail({
        pageSize: this.limit,
        pageNo: this.currentPage
      });
      if (res.status == "200") {
        this.dataTable.loading = false;
        this.dataTable.data = [];
        this.count = res.data.total;
        res.data.list.forEach(item => {
          const data = {};
          data.tOvuola = item.tOvuola;
          data.rOvuola = item.rOvuola;
          data.wOvuola = item.wOvuola;
          data.pOvuola = item.pOvuola;
          data.tHead = item.tHead;
          data.rHead = item.rHead;
          data.wHead = item.wHead;
          data.pHead = item.pHead;
          data.tStraw = item.tStraw;
          data.rStraw = item.rStraw;
          data.wStraw = item.wStraw;
          data.pStraw = item.pStraw;
          data.tConsult = item.tConsult;
          data.pubConsult = item.pubConsult;
          data.pingConsult = item.pingConsult;
          data.time =
            format("yyyy.MM.dd", new Date(item.startTime)) +
            "-" +
            format("MM.dd", new Date(item.endTime));
          this.dataTable.data.push(data);
        });
      }
    }
  }
};
</script>
